package com.example.shopping;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

//import com.mayuhao.homework.R;

import java.util.ArrayList;
import java.util.List;

public class ShoppingMallAdapter extends RecyclerView.Adapter<ShoppingMallAdapter.myViewHolder> {

    private List<Goods> data = new ArrayList<>();
    private Context context;

    public ShoppingMallAdapter(List<Goods> data, Context context) {
        this.data = data;
        this.context = context;
    }


    @NonNull
    @Override
    public myViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.recyclerview_shopping_item_crud, null);

        return new myViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull myViewHolder holder, int position) {
        holder.tvShowName.setText(data.get(position).getName());
        holder.tvShowPrice.setText(data.get(position).getPrice());
        holder.tvShowCount.setText(data.get(position).getCount());
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    public class myViewHolder extends RecyclerView.ViewHolder {

        private TextView tvShowName, tvShowPrice, tvShowCount;

        public myViewHolder(@NonNull View itemView) {
            super(itemView);
            tvShowName = itemView.findViewById(R.id.tv_name);
            tvShowPrice = itemView.findViewById(R.id.tv_price);
            tvShowCount = itemView.findViewById(R.id.tv_number);
        }
    }
}
